<template>
    <h1>医生列表</h1>
    医生名称:
    <input type="text" v-model="dname"/>
    职称:
    <select v-model="zhicheng">
        <option value="">--请选择--</option>
        <option value="主治医生">主治医生</option>
        <option value="非主治医生">非主治医生</option>
        <option value="主刀医生">主刀医生</option>
        <option value="非主刀医生">非主刀医生</option>
     </select>
    <input type="button" value="查询" @click="Show"/>

    <table class="table" border="1">
        <thead>
            <tr>
                <td>医生名称</td>
                <td>科室</td>
                <td>职称</td>
                <td>第一职业医院</td>
                <td>是否开通账号</td>
                <td>类型</td>
                <td>创建时间</td>
                <td>更新时间</td>
                <td>医生照片</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in Info">
                <td>{{item.dName}}</td>
                <td>{{item.kName}}</td>
                <td>{{item.zhiCheng}}</td>
                <td>{{item.xueli}}</td>
                <td>{{item.isKai==0?"已开通":"未开通"}}</td>
                <td>{{item.type}}</td>
                <td>{{item.dCraDate.substring(0,10)}}</td>
                <td>{{item.dGengDate.substring(0,10)}}</td>
                <td>{{item.img}}</td>
                <td>
                    <input type="button" value="删除" @click="Del(item.id)"/>
                    <input type="button" value="查看" @click="kan(item.id)"/>
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import { ref,onMounted } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
onMounted(()=>{
    Show();
})

const Info=ref([{
    "id": 0,
    "dName": "",
    "kId": 0,
    "xueli": "",
    "zhiCheng": "",
    "isKai": 0,
    "type": "",
    "img": "",
    "dCraDate": "",
    "dGengDate": "",
    "isDel": 0,
    "kName": "string"
}])

const dname=ref("")
const zhicheng=ref("")

const Show=()=>{
    axios.get("https://localhost:7199/api/Docater/GetAll",{
        params:{
            dname:dname.value,
            zhicheng:zhicheng.value
        }
    })
    .then(res=>{
        Info.value=res.data
    })
    .catch(error=>{
        console.log(error);
    })
}

const Del=(id:number)=>{
    if(confirm("确定删除吗？")){
        axios.delete("https://localhost:7199/api/Docater/Delete",{
        params:{
            id:id
        }
    })
    .then(res=>{
        if(res.data>0){
            alert("删除成功！")
            Show();
        }
        else{
            alert("删除失败")
        }
    })
    .catch(error=>{
        console.log(error);
    })
    }
}

const router=useRouter();
const kan=(id:number)=>{
    router.push({
        name:'KanDocater',
        params:{
            id:id
        }
    })
}

</script>